package com.diankangwo.dao.impl;

import cn.beecloud.bean.BCOrder;
import com.diankangwo.dao.OrderMomentPayDAO;
import com.diankangwo.util.BeecloudPay;
import com.diankangwo.util.BeecloudPayUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Repository
public class OrderMomentPayDAOImpl implements OrderMomentPayDAO {

	private static final Logger LOG = Logger.getLogger(OrderMomentPayDAOImpl.class);
	
	private BeecloudPay pay = new BeecloudPay(); // 主要返回URL或HTML

	private BeecloudPayUtil util = new BeecloudPayUtil(); // 返回实体,调用者自行处理结果
	
	@Override
	public BCOrder wechatQrsPay(Integer totalFee, String billNo, String title) {
		try {
			return util.wechatQrsPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("微信扫码支付异常:"+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public Map<String, String> wechatJSAPIPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.wechatJSAPIPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("微信公众号支付异常："+e.getMessage()+"，订单号："+billNo );
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public BCOrder unionWebPay(Integer totalFee, String billNo, String title) {
		try {
			return util.unionWebPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("银联网银支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}
	
	@Override
	public BCOrder unionWapPay(Integer totalFee, String billNo, String title) {
		try {
			return util.unionWapPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("银联网银支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public BCOrder aliPay(Integer totalFee, String billNo, String title, Map<String, Object> optional) {
		try {
			return util.aliPay(totalFee, billNo, title, optional);
		} catch (Exception e) {
			LOG.debug("阿里网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String aliQrPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.aliQrPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("阿里扫码异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public BCOrder aliwapPay(Integer totalFee, String billNo, String title, String returnType) {
		try {
			return util.aliwapPay(totalFee, billNo, title);
			//return pay.aliwapPay(totalFee, billNo, title, returnType);
		} catch (Exception e) {
			LOG.debug("阿里移动网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String kqWebPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.kqWapPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("快钱移动网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String kqWapPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.kqWapPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("快钱移动网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String jdWebPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.jdWebPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("京东网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String jdWapPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.jdWapPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("京东移动网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String yeeWebPay(Integer totalFee, String billNo, String title, String returnType) {
		try {
			return pay.yeeWebPay(totalFee, billNo, title, returnType);
		} catch (Exception e) {
			LOG.debug("易宝网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String yeeWapPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.yeeWapPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("易宝移动网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String bdWebPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.bdWebPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("百度网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String bdWapPay(Integer totalFee, String billNo, String title) {
		try {
			return pay.bdWapPay(totalFee, billNo, title);
		} catch (Exception e) {
			LOG.debug("百度移动网页支付异常："+e.getMessage()+"，订单号："+billNo);
			e.printStackTrace();
			return null;
		}
	}

}
